package com.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AnnoAdvice {

    //切点
    @Pointcut("execution(* com.dao.impl.UserDaoImpl.*(..))")
    public void pointCut() {

    }
    //前置通知
    @Before("pointCut()")
    public void before(JoinPoint joinPoint) {
        System.out.print("前置通知");
        System.out.print("目标类是；"+ joinPoint.getTarget());
        System.out.println("被植入增强处理的目标方法是；"+  joinPoint.getSignature().getName());
    }
    //环绕通知
    @Around("pointCut()")
    public Object around(ProceedingJoinPoint Point) throws Throwable {
        System.out.print("这是环绕通知之前的部分");
        //调用方法
        Object object = Point.proceed();
        System.out.print("这是环绕通知之后的部分");
        return object;
    }
    //异常通知
    @AfterThrowing("pointCut()")
    public void afterThrowing() {
        System.out.println("异常通知");
        }
        //后置通知
    @After("pointCut()")
    public void after(){
        System.out.println("后置通知");
    }
}
